home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / support / hash.scm < prev    next >
Encoding:
Text File  |  1994-09-27  |  722 b   |  32 lines  |  [TEXT/CCL2]

  1.  
  2. ;;; This is a VERY SIMPLE hashing routine for structure printing.
  3.  
  4. (define *structure-hash-table* '())
  5.  
  6. (define (structure-hash s)
  7.   (cond ((null? *structure-hash-table*)
  8.      (setf *structure-hash-table* (list s))
  9.      0)
  10.     (else
  11.      (search-structure-hash-table *structure-hash-table* s 0))))
  12.  
  13. (define (search-structure-hash-table tbl s n)
  14.   (cond ((eq? (car tbl) s) n)
  15.     ((null? (cdr tbl))
  16.      (setf (cdr tbl) (list s))
  17.      (+ n 1))
  18.     (else (search-structure-hash-table (cdr tbl) s (+ n 1)))))
  19.  
  20. (define (structure-unhash i)
  21.   (search-structure-table *structure-hash-table* i))
  22.  
  23. (define (search-structure-table tbl i)
  24.   (if (null? tbl)
  25.       '()
  26.       (if (eqv? i 0)
  27.       (car tbl)
  28.       (search-structure-table (cdr tbl) (- i 1)))))
  29.  
  30.  
  31.      
  32.